package graph.entities;

import static ogl.vecmathimp.FactoryDefault.vecmath;
import graph.Entity;
import graph.Part;
import ogl.vecmath.Matrix;
import ogl.vecmathimp.MatrixImp;

public class Rotor extends Entity {
	private float angleX = 0f;
    private float angleY = 0f;
    private float angleZ = 0f;

	public Rotor(Part p) {
		super(p);
	}
	
	@Override
	public void simulate(EntityType et, float elapsed) {		
		// Increase the angle with a speed of 90 degrees per second.
		if (et == EntityType.RotationX) {
			angleX += 40 * elapsed;
		}
		else if (et == EntityType.RotationY) {
			angleY += 40 * elapsed;
		}
		else if (et == EntityType.RotationZ) {
			angleZ += 40 * elapsed;
		}
		else if (et == EntityType.RotationMX) {
			angleX -= 40 * elapsed;
		}
		else if (et == EntityType.RotationMY) {
			angleY -= 40 * elapsed;
		}
		else if (et == EntityType.RotationMZ) {
			angleZ -= 40 * elapsed;
		}	
		
		MatrixImp modelMatrix = super.getPart().getMatrix().getTranslation();
		modelMatrix = (MatrixImp) modelMatrix
								.mult(vecmath.rotationMatrix(0, 1, 0, angleY))
								.mult(vecmath.rotationMatrix(1, 0, 0, angleX))
								.mult(vecmath.rotationMatrix(0, 0, 1, angleZ));
		
		this.getPart().setMatrix(modelMatrix);
	}

}
